package com.syh.bishe.mapper;

import com.syh.bishe.pojo.CarbonCredits;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.syh.bishe.pojo.Transactions;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author syh
 * @since 2024-07-02
 */
@Mapper
public interface CarbonCreditsMapper extends BaseMapper<CarbonCredits> {

    @Update("update carbon_credits set credit_amount = credit_amount - #{emissionAmount} where company_id = #{companyId}")
    void updateCreditAmount(Integer companyId, BigDecimal emissionAmount);

    @Update("update carbon_credits set credit_amount = credit_amount + #{emissionAmount} where company_id = #{companyId}")
    void updateCreditAmountAdd(Integer companyId, BigDecimal emissionAmount);

    @Select("select credit_amount from carbon_credits where company_id = #{companyId}")
    BigDecimal getCreditAmount(Integer companyId);

    @Select("select account from carbon_credits where company_id = #{companyId}")
    BigDecimal getAccount(Integer companyId);

    @Update("update carbon_credits set account = account + #{account} where company_id = #{companyId}")
    void updateAccount(CarbonCredits carbonCredits);

    @Update("update carbon_credits set account = account - #{finalSum} where company_id = #{buyerId}")
    void updateAccount_s(Transactions transactions);
    @Update("update carbon_credits set account = account + #{finalSum} where company_id = #{sellerId}")
    void updateAccount_a(Transactions transactions);
    @Update("update carbon_credits set account = account + #{finalSum} where company_id = #{buyerId}")
    void updateAccount_add_buy(Transactions transactions);
    @Update("update carbon_credits set account = account - #{finalSum} where company_id = #{sellerId}")
    void updateAccount_add_sell(Transactions transactions);
}
